<template>
<!--  <el-form-item label="父属性名">
    <el-select v-model="optionModel.parentKeyName" :reserve-keyword="false"
               placeholder="选择或者输入"
               allow-create default-first-option clearable filterable>
      <el-option v-for="item in fieldList" :key="item" :label="item" :value="item"/>
    </el-select>
  </el-form-item>-->

  <el-form-item label="Key中文" v-if="showFieldAttr('label') && selectedWidget.type !='static-text'">
    <el-input v-model="optionModel.label" @change="changeLabel">
      <template #append>
        <el-button @click="setFieldName()">设置KEY</el-button>
      </template>
    </el-input>
  </el-form-item>
  <el-form-item label="Key" v-if="showFieldAttr('fieldName')">
    <el-input v-model="optionModel.fieldName"></el-input>
  </el-form-item>
  <el-form-item label="文本内容" v-if="selectedWidget.type =='static-text'">
    <el-button type="primary"  @click="editFillText()">编辑文本</el-button>
  </el-form-item>
<!--  <el-form-item label="图片" v-if="showFieldAttr('pictureAddress')">
    <el-image style="width: 100%;" :src="optionModel.pictureAddress" fit="fill" v-if="optionModel.pictureAddress"/>
    <input type="file" id="fileInput" accept="image/*" @change="handleImgSuccess"/>
  </el-form-item>-->
  <el-form-item label="推送至表单项目" v-if="showFieldAttr('syncData')">
    <el-form-item label-width="0">
      <div v-for="(item,index) in optionModel.syncData" :key="index" style="width: 100%;margin-bottom: 5px">
        <el-button type="primary" style="min-width: 120px;max-width: 230px;" @click="editReport(item,index)">{{ item.reportId }}</el-button>
        <el-button circle plain size="small" type="danger"
                   icon="el-icon-minus" class="col-delete-button" @click="deleteReport(index)"></el-button>
      </div>
      <el-button link type="primary" @click="addReport()" style="margin-left: 10px;">增加报表ID</el-button>
    </el-form-item>
  </el-form-item>
  <el-form-item label="前缀" v-if="showFieldAttr('preSuffix') && selectedWidget.type !='static-text'">
    <el-input v-model="optionModel.preSuffix"></el-input>
  </el-form-item>
  <el-form-item label="后缀" v-if="showFieldAttr('afterSuffix')">
    <el-input v-model="optionModel.afterSuffix"></el-input>
  </el-form-item>
  <div v-if="showFieldAttr('bindingData')">
    <el-divider class="custom-divider-margin-top">绑定项目选项</el-divider>
    <el-form-item label="是否换行" v-if="showFieldAttr('wrapDisplay')">
      <el-switch v-model="optionModel.wrapDisplay"></el-switch>
    </el-form-item>
    <el-form-item label="数据来源">
      <el-select v-model="optionModel.bindingData.type" placeholder="请输入数据来源" clearable filterable>
        <el-option label="字典表" value="xcodemap" />
        <el-option label="自定义SQL语句" value="dynamicSql" />
        <el-option label="固定值" value="static" />
        <el-option label="第三方接口" value="thirdParty" />
      </el-select>
    </el-form-item>
    <el-form-item label="参数" v-if="optionModel.bindingData?.type == 'dynamicSql'">
      <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" v-model="optionModel.bindingData.args"></el-input>
    </el-form-item>
    <el-form-item label="字典" v-if="optionModel.bindingData?.type == 'xcodemap'">
      <el-select v-model="optionModel.bindingData.args" placeholder="请选择字典" clearable filterable @change="changeCommDict">
        <el-option v-for="(item,index) in commDictList" :label="item.COMM_NAME" :value="item.COMM_CODE"/>
      </el-select>
    </el-form-item>
    <el-form-item label="选项组ID" v-if="showFieldAttr('groupId')">
      <el-input v-model="optionModel.groupId"></el-input>
    </el-form-item>
    <el-divider class="custom-divider-margin-top">选项</el-divider>
    <el-form-item label="" label-width="0" v-if="optionModel.bindingData?.type == 'static'">
      <el-row v-for="(item,index) in optionModel.bindingData.option" v-if="selectedWidget.type != 'cascader'"
              :key="index" style="width: 100%;margin-bottom: 5px;display: flex;">
        <el-col :span="6">
          <el-form-item label="Key" label-width="25" >
            <el-input v-model="item.fieldName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="Key中文" label-width="50" >
            <el-input v-model="item.label"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="值" label-width="16" >
            <el-input v-model="item.value"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-button circle plain size="small" type="danger"
                     icon="el-icon-minus" class="col-delete-button" @click="deleteBindingDataOption(index)"></el-button>
        </el-col>
      </el-row>
      <el-button link type="primary" @click="importOptions" v-if="selectedWidget.type != 'cascader'">导入选项</el-button>
      <el-button link type="primary" @click="importCascaderOptions" v-if="selectedWidget.type == 'cascader'">导入选项</el-button>
      <el-button link type="primary" @click="addBindingDataOption()" style="margin-left: 10px;" v-if="selectedWidget.type != 'cascader'">增加选项</el-button>
      <el-button link type="primary" @click="bindKey()" style="margin-left: 10px;" v-if="selectedWidget.type != 'cascader'">绑定key</el-button>
    </el-form-item>
  </div>
  <el-form-item label="显示格式" v-if="selectedWidget.type =='date'">
    <el-select v-model="optionModel.otherNonGenericAttributes.showDateFormat" placeholder="请选择日期格式">
      <el-option v-for="item in dateFormatList" :key="item.value" :label="item.label" :value="item.value" clearable></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="绑定值格式" v-if="selectedWidget.type =='date'">
    <el-select v-model="optionModel.otherNonGenericAttributes.backDateFormat" placeholder="请选择绑定值格式">
      <el-option v-for="item in dateFormatList" :key="item.value" :label="item.label" :value="item.value" clearable></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="日期类型" v-if="selectedWidget.type =='date'">
    <el-select v-model="optionModel.otherNonGenericAttributes.dateType" placeholder="请选择日期类型">
      <el-option v-for="item in dateTypeList" :key="item.value" :label="item.label" :value="item.value" clearable></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="最大" v-if="selectedWidget.type =='slider'">
    <el-input-number v-model="optionModel.otherNonGenericAttributes.max"></el-input-number>
  </el-form-item>
  <el-form-item label="最小" v-if="selectedWidget.type =='slider'">
    <el-input-number v-model="optionModel.otherNonGenericAttributes.min"></el-input-number>
  </el-form-item>
  <el-form-item label="步长" v-if="selectedWidget.type =='slider'">
    <el-input-number v-model="optionModel.otherNonGenericAttributes.stepSize"></el-input-number>
  </el-form-item>
  <el-divider>字段配置</el-divider>
<!--  <el-form-item label="是否动态列" v-if="showFieldAttr('dynamicColumn')">
    <el-switch v-model="optionModel.dynamicColumn"></el-switch>
  </el-form-item>-->
<!--  <el-form-item label="类型" v-if="showFieldAttr('fieldType')">
    <el-input v-model="optionModel.fieldType" disabled></el-input>
  </el-form-item>-->
  <el-form-item label="提示" v-if="showFieldAttr('hover')">
    <el-input v-model="optionModel.hover"></el-input>
  </el-form-item>
  <el-form-item label="对齐方式" v-if="showFieldAttr('textAlign')">
    <el-select v-model="optionModel.textAlign" clearable placeholder="请选择对齐方式">
      <el-option label="居左" value="left" />
      <el-option label="居中" value="center" />
      <el-option label="居右" value="right" />
    </el-select>
  </el-form-item>
  <el-form-item label="项目附加标记" v-if="showFieldAttr('additionalFlag')">
    <el-select v-model="optionModel.additionalFlag" @change="changeAdditionalFlag" clearable placeholder="请选择项目附加标记">
      <el-option label="体温" value="temperature" />
      <el-option label="脉搏" value="pulse" />
      <el-option label="呼吸" value="breath" />
      <el-option label="心率" value="XL" />
      <el-option label="降温后体温" value="JWHTW" />
    </el-select>
  </el-form-item>
  <el-form-item label="正则表达式" v-if="showFieldAttr('rules')">
    <el-select v-model="optionModel.rules.regularExpression" :reserve-keyword="false"
               placeholder="选择或者输入"
               allow-create default-first-option clearable filterable>
      <el-option v-for="option in ruleList" :key="option.value" :label="option.label" :value="option.value"/>
    </el-select>
  </el-form-item>
  <el-form-item label="校验提示" v-if="showFieldAttr('rules')">
    <el-input v-model="optionModel.rules.failurePrompt"></el-input>
  </el-form-item>
  <el-form-item label="表单字段映射" v-if="showFieldAttr('mainFieldMapping')">
    <el-select v-model="optionModel.mainFieldMapping" clearable placeholder="请选择表单字段映射">
      <el-option label="主表日期" value="date" />
      <el-option label="主表时间" value="time" />
      <el-option label="主表日期时间" value="dateTime" />
    </el-select>
  </el-form-item>
  <el-form-item label="项目属性标识" v-if="showFieldAttr('attrTag')">
    <el-select v-model="optionModel.attrTag" clearable placeholder="请选择项目属性标识">
<!--      <el-option label="总分项目" value="totalScore" />
      <el-option label="出量项目" value="C" />
      <el-option label="入量项目" value="R" />
      <el-option label="普通项目" value="N" />
      <el-option label="导管" value="D" />-->
      <el-option v-for="item in attrTags" :key="item.value" :label="item.label" :value="item.value"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="是否多行处理" v-if="showFieldAttr('multiLines')">
    <el-switch v-model="optionModel.multiLines"></el-switch>
  </el-form-item>
  <el-form-item label="携带字段" v-if="showFieldAttr('multiLines')">
    <el-select v-model="optionModel.multiCarryFields" multiple
               placeholder="请选择携带字段" clearable filterable>
      <el-option v-for="item in fieldList" :key="item.value" :label="item.label" :value="item.value"/>
    </el-select>
  </el-form-item>
<!--  <el-form-item label="表格宽" v-if="showFieldAttr('tableWidth')">
    <el-input v-model="optionModel.tableWidth"></el-input>
  </el-form-item>
  <el-form-item label="表格高" v-if="showFieldAttr('tableHeight')">
    <el-input v-model="optionModel.tableHeight"></el-input>
  </el-form-item>-->
  <el-form-item label="左边距" v-if="showFieldAttr('leftMargin')">
    <el-input-number v-model="optionModel.leftMargin"></el-input-number>
  </el-form-item>
  <el-form-item label="右边距" v-if="showFieldAttr('rightMargin')">
    <el-input-number v-model="optionModel.rightMargin"></el-input-number>
  </el-form-item>
  <el-form-item label="是否只读" v-if="showFieldAttr('readOnly')">
    <el-switch v-model="optionModel.readOnly"></el-switch>
  </el-form-item>
  <el-form-item label="是否可见" v-if="showFieldAttr('visible')">
    <el-switch v-model="optionModel.visible"></el-switch>
  </el-form-item>
  <el-form-item label="展示控制" v-if="showFieldAttr('showCtrl')">
    <el-select v-model="optionModel.showCtrl" placeholder="请选择展示控制">
      <el-option label="全部展示" :value="0"/>
      <el-option label="仅新增界面展示" :value="1"/>
      <el-option label="仅编辑界面展示" :value="2"/>
    </el-select>
  </el-form-item>
<!--  <el-form-item label="是否可用" v-if="showFieldAttr('enable')">
    <el-switch v-model="optionModel.enable"></el-switch>
  </el-form-item>-->
  <el-form-item label="是否必填" v-if="showFieldAttr('required')">
    <el-switch v-model="optionModel.required"></el-switch>
  </el-form-item>
  <el-form-item label="表格展示" v-if="showFieldAttr('tableShow')">
    <el-switch v-model="optionModel.tableShow"></el-switch>
  </el-form-item>
  <el-form-item label="可否打印" v-if="showFieldAttr('printAble')">
    <el-switch v-model="optionModel.printAble"></el-switch>
  </el-form-item>
  <el-form-item label="是否可搜索" v-if="showFieldAttr('searchAble')">
    <el-switch v-model="optionModel.searchAble"></el-switch>
  </el-form-item>
  <el-form-item label="不加载上一条记录" v-if="showFieldAttr('notLoadLastRecord')">
    <el-switch v-model="optionModel.notLoadLastRecord"></el-switch>
  </el-form-item>
  <el-form-item label="计算公式" v-if="showFieldAttr('calculatedFields')">
    <el-input v-model="optionModel.calculatedFields">
      <template #append>
        <el-button @click="goEditCalculated('fieldDef',optionModel.calculatedFields)">编辑</el-button>
      </template>
    </el-input>
<!--    <calculate-editor v-model="optionModel.calculatedFields"></calculate-editor>-->
  </el-form-item>

  <el-form-item label="默认值" v-if="showFieldAttr('defaultValue')">
    <el-input autosize type="textarea" v-model="optionModel.defaultValue"></el-input>
  </el-form-item>
  <div v-if="showFieldAttr('initializedExpressions')">
    <el-divider class="custom-divider-margin-top">初始化项目值</el-divider>
    <el-form-item label="数据来源">
      <el-select v-model="optionModel.initializedExpressions.dataSource" placeholder="请输入数据来源" clearable filterable>
        <el-option label="前端获取" value="front" />
        <el-option label="请求后端" value="back" />
      </el-select>
    </el-form-item>
    <el-form-item label="请求参数">
      <el-input v-model="optionModel.initializedExpressions.requestArgs"></el-input>
    </el-form-item>
    <el-form-item label="计算表达式">
      <el-input v-model="optionModel.initializedExpressions.expression">
        <template #append>
          <el-button @click="goEditCalculated('initializedExpressions',optionModel.initializedExpressions.expression)">编辑</el-button>
        </template>
      </el-input>
    </el-form-item>
    <el-form-item label="条件" label-width="35">
      <el-row v-for="(item,index) in optionModel.initializedExpressions.range" :key="index" style="width: 100%;margin-bottom: 5px;display: flex;">
        <el-col :span="7">
          <el-form-item label="最大" label-width="30" >
            <el-input v-model="item.max"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="最小" label-width="30" >
            <el-input v-model="item.min"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="结果" label-width="30" >
            <el-input v-model="item.result"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-button circle plain size="small" type="danger"
                     icon="el-icon-minus" class="col-delete-button" @click="deleteRange(index)"></el-button>
        </el-col>
      </el-row>
      <el-button link type="primary" @click="addRange()" style="margin-left: 10px;">增加条件</el-button>
    </el-form-item>
  </div>

  <div v-if="showFieldAttr('changeEvent')">
    <el-divider class="custom-divider-margin-top">数据联动</el-divider>
    <el-form-item label-width="0">
      <div v-for="(item,index) in optionModel.changeEvent" :key="index" style="width: 100%;margin-bottom: 5px">
        <el-button type="primary" style="min-width: 150px;max-width: 230px;" @click="editEvent(item,index)">{{ item.type }}</el-button>
        <el-button circle plain size="small" type="danger"
                   icon="el-icon-minus" class="col-delete-button" @click="deleteEvent(index)"></el-button>
      </div>
      <el-button link type="primary" @click="addEvent()" style="margin-left: 10px;">增加联动事件</el-button>
    </el-form-item>
  </div>

  <el-dialog title="编辑事件" v-model="openEvent" width="1200" append-to-body>
    <el-form ref="eventForm" :model="eventForm" :rules="eventRules" label-width="80px">
      <el-row>
<!--        <el-col :span="12">
          <el-form-item label="事件名称" prop="name">
            <el-input v-model="eventForm.name" placeholder="请输入事件名称" maxlength="10"/>
          </el-form-item>
        </el-col>-->
        <el-col :span="12">
          <el-form-item label="事件类型" prop="type">
            <el-select v-model="eventForm.type" placeholder="请输入事件类型" clearable filterable>
              <el-option label="值变动" value="valueChange" />
              <el-option label="双击" value="doubleClick" />
              <el-option label="键盘事件" value="keyboardEvent" />
              <el-option label="值变动-不间断" value="valueChange-U" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="eventForm.type == 'valueChange' || eventForm.type == 'valueChange-U'">
          <el-form-item label="条件">
            <el-row v-for="(item,index) in eventForm.condition" :key="index" style="width: 100%;margin-bottom: 15px;display: flex;">
              <el-col :span="6">
                <el-form-item label="Key">
                  <el-select v-model="item.fieldName" :reserve-keyword="false"
                             placeholder="选择或者输入"
                             allow-create default-first-option clearable filterable>
                    <el-option v-for="option in fieldList" :key="option.value" :label="option.label" :value="option.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="比较">
                  <el-select v-model="item.comparisonType" placeholder="请选择" clearable filterable>
                    <el-option v-for="comparisonType in  comparisonTypeList" :key="comparisonType.ITEM_CODE"
                               :label="comparisonType.ITEM_NAME" :value="comparisonType.ITEM_CODE" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="值">
                  <el-select v-model="item.value" :reserve-keyword="false" multiple  placeholder="输入后按回车录入"
                      allow-create default-first-option clearable filterable>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="连接">
                  <el-radio-group v-model="item.linkType">
                    <el-radio-button label="or" value="or" />
                    <el-radio-button label="and" value="and" />
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-button circle plain size="small" type="danger"
                           icon="el-icon-minus" class="col-delete-button" @click="deleteCondition(index)"></el-button>
              </el-col>
            </el-row>
            <el-button link type="primary" @click="addCondition()" style="margin-left: 40px;">增加条件</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="eventForm.type == 'keyboardEvent'">
          <el-form-item label="条件">
            <el-row v-for="(item,index) in eventForm.condition" :key="index" style="width: 100%;margin-bottom: 15px;display: flex;">
              <el-col :span="20">
                <el-form-item label="按钮">
                  <el-select v-model="item.value" :reserve-keyword="false" multiple  placeholder="输入后按回车录入"
                             allow-create default-first-option clearable filterable>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-button circle plain size="small" type="danger"
                           icon="el-icon-minus" class="col-delete-button" @click="deleteCondition(index)"></el-button>
              </el-col>
            </el-row>
            <el-button link type="primary" @click="addCondition()" style="margin-left: 40px;">增加条件</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-divider class="custom-divider-margin-top">动作</el-divider>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                  type="primary"
                  plain
                  icon="el-icon-plus"
                  size="small"
                  @click="addAction"
              >新增动作
              </el-button>
            </el-col>
          </el-row>
          <el-table :data="eventForm.actions">
            <el-table-column label="影响类型" align="center" prop="name">
              <template #default="scope">
                <el-select v-model="scope.row.name" clearable placeholder="请选择影响类型" filterable @change="changeActionName(scope.row)">
                  <el-option label="只读控制" value="readOnlyCtrl" />
                  <el-option label="可见控制" value="visibleCtrl" />
                  <el-option label="刷新护理单" value="refreshFuncCtrl" />
                  <el-option label="跳转护理单" value="jumpWinCtrl" />
                  <el-option label="更新字段值" value="updateValue" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="被影响单元" align="center">
              <template #default="scope">
                <el-select v-model="scope.row.refreshField" :reserve-keyword="false" multiple
                           placeholder="请选择被影响单元" v-if="scope.row.name == 'readOnlyCtrl' || scope.row.name == 'visibleCtrl' || scope.row.name == 'updateValue'"
                           allow-create default-first-option clearable filterable>
                  <el-option v-for="item in fieldList" :key="item.value" :label="item.label" :value="item.value"/>
                </el-select>
                <el-select v-model="scope.row.funcNo" clearable @change="changeNursingSheet(scope.row)"
                           placeholder="请选择会连" v-if="scope.row.name == 'refreshFuncCtrl'" filterable>
                  <el-option v-for="item in nursingSheetList" :key="item.FUNCNO" :label="item.TITLE" :value="item.FUNCNO"/>
                </el-select>
                <el-select v-model="scope.row.jumpWinNo" clearable
                           placeholder="请选择护理单" v-if="scope.row.name == 'jumpWinCtrl'" filterable>
                  <el-option v-for="item in winList" :key="item.WINNO" :label="item.TITLE" :value="item.WINNO"/>
                </el-select>
<!--                <el-input v-model="scope.row.jumpWinNo" v-if="scope.row.name == 'jumpWinCtrl'"></el-input>-->
              </template>
            </el-table-column>
            <el-table-column label="参数" align="center" prop="name">
              <template #default="scope">
                <el-select v-model="scope.row.mappingFieldName" clearable @change="changeMappingField(scope.row)"
                           placeholder="请选择参数" v-if="scope.row.name == 'refreshFuncCtrl'" filterable>
                  <el-option v-for="item in mappingFieldList" :key="item.mappingFieldName" :label="item.label" :value="item.value"/>
                </el-select>
                <el-input v-model="scope.row.changeTo" v-if="scope.row.name == 'updateValue'">
                  <template #append>
                    <el-button @click="goEditCalculated('updateFieldValue',scope.row.changeTo,scope.row)">编辑</el-button>
                  </template>
                </el-input>
                <el-radio-group v-model="scope.row.openAs" v-if="scope.row.name == 'jumpWinCtrl'">
                  <el-radio value="table">以表格展示</el-radio>
                  <el-radio value="form">以表单展示</el-radio>
                </el-radio-group>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template #default="scope">
<!--                <el-button
                    size="small"
                    type="text"
                    icon="el-icon-edit"
                    @click="editAction(scope.row)"
                >修改
                </el-button>-->
                <el-button
                    size="small"
                    type="text"
                    icon="el-icon-delete"
                    @click="deleteAction(scope.$index)"
                >删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" align="center" style="margin-top: 30px">
      <el-button type="primary" @click="submitBtnForm">确 定</el-button>
      <el-button @click="openEvent = false">取 消</el-button>
    </div>
  </el-dialog>

<!--  <el-dialog title="编辑动作" v-model="openAction" width="1200" append-to-body>
    <el-form ref="actionForm" :model="actionForm" :rules="actionRules" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="操作类型" prop="name">
            <el-select v-model="actionForm.name" clearable filterable>
              <el-option label="可用控制" value="readOnlyCtrl" />
              <el-option label="可见控制" value="visibleCtrl" />
&lt;!&ndash;              <el-option label="更新值控制" value="updateFieldValue" />&ndash;&gt;
              <el-option label="刷新模块控制" value="refreshFuncCtrl" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="动作描述">
            <el-input v-model="actionForm.des"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="跳转窗口号">
            <el-input v-model="actionForm.refresh.winNo"></el-input>
          </el-form-item>
        </el-col>
&lt;!&ndash;        <el-col :span="12">
          <el-form-item label="加载组件">
            <el-input v-model="actionForm.refresh.componentName"></el-input>
          </el-form-item>
        </el-col>&ndash;&gt;
        <el-col :span="12">
          <el-form-item label="请求类型" prop="requestType">
            <el-select v-model="actionForm.refresh.requestParams.requestType" placeholder="请选择" clearable filterable>
              <el-option label="前端参数" value="frontArgs" />
              <el-option label="字典表" value="xcodemap" />
              <el-option label="自定义SQL语句" value="dynamicSql" />
              <el-option label="第三方接口" value="thirdParty" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="请求参数">
            <el-input v-model="actionForm.refresh.requestParams.args"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="actionForm.name == 'refreshFuncCtrl'">
          <el-form-item label="主表参数" prop="mainArgs">
            <el-select v-model="actionForm.refresh.mainArgs" multiple :reserve-keyword="false"
                       placeholder="输入后按下回车键"
                       allow-create default-first-option clearable filterable></el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="actionForm.name == 'refreshFuncCtrl'">
          <el-form-item label="子表参数" prop="detailArgs">
            <el-select v-model="actionForm.refresh.detailArgs" multiple :reserve-keyword="false"
                       placeholder="输入后按下回车键"
                       allow-create default-first-option clearable filterable></el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="actionForm.name == 'refreshFuncCtrl'">
          <el-form-item label="功能模块" prop="refreshFunc">
            <el-select v-model="actionForm.refresh.refreshFunc" multiple :reserve-keyword="false"
                       placeholder="输入后按下回车键"
                       allow-create default-first-option clearable filterable></el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="actionForm.name == 'readOnlyCtrl' || actionForm.name == 'visibleCtrl'">
          <el-form-item label="刷新Key" prop="refreshField">
            <el-select v-model="actionForm.refresh.refreshField" multiple :reserve-keyword="false"
                       placeholder="输入后按下回车键"
                       allow-create default-first-option clearable filterable></el-select>
          </el-form-item>
        </el-col>
&lt;!&ndash;        <el-col :span="24" v-if="actionForm.name == 'updateFieldValue'">
          <el-form-item label="更新数据">
            <el-row v-for="(item,index) in actionForm.refresh.updateFieldValue" :key="index" style="width: 100%;margin-bottom: 15px;display: flex;">
              <el-col :span="5">
                <el-form-item label="Key">
                  <el-select v-model="item.fieldName" :reserve-keyword="false"
                             placeholder="选择或者输入"
                             allow-create default-first-option clearable filterable>
                    <el-option v-for="option in fieldList" :key="option" :label="option" :value="option"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="更新表达式">
                  <el-input v-model="item.changeTo">
                    <template #append>
                      <el-button @click="goEditCalculated('updateFieldValue',item.changeTo,item)">编辑</el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-button circle plain size="small" type="danger"
                           icon="el-icon-minus" class="col-delete-button" @click="deleteUpdateField(index)"></el-button>
              </el-col>
            </el-row>
            <el-button link type="primary" @click="addUpdateField()" style="margin-left: 40px;">增加条件</el-button>
          </el-form-item>
        </el-col>&ndash;&gt;
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" align="center">
      <el-button type="primary" @click="submitActionForm">确 定</el-button>
      <el-button @click="openAction = false">取 消</el-button>
    </div>
  </el-dialog>-->

  <el-dialog title="计算表达式" v-model="openCalculation" append-to-body width="1200">
    <el-row :gutter="20">
      <el-col :span="16">
        <el-input v-model="calculation"
                  :rows="26"
                  type="textarea"
                  ref="calculationInput"
                  placeholder="请输入表达式"></el-input>
      </el-col>
      <el-col :span="8" >
        <el-input v-model="calculationFilterString"
                  placeholder="搜索"></el-input>
        <el-tabs v-model="activeNames" class="demo-tabs" @tab-change="changeCalculation">
          <el-tab-pane label="表单元素" name="first">
            <el-checkbox  v-model="checkAllCalculation" @change="checkAllCalculationFieldList"
                          style="margin-left: 10px;margin-top: 10px">全选</el-checkbox>
            <div class="calculationFilter">
              <el-checkbox-group v-model="selectCalculationList" style="display: block">
                <el-checkbox v-for="item in calculationFieldList" :key="item.code" class="check_box" :value="item.code">
                  <div @click.prevent="selectCalculationField(item.code)">{{item.commit}}</div>
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-tab-pane>
          <el-tab-pane label="全局元素" name="second">
<!--              <div v-for="item in globalParamList" :key="item" @click="selectCalculationField(item.code)">{{item.commit}}</div>-->
            <el-checkbox  v-model="checkAllCalculation" @change="checkAllCalculationFieldList"
                          style="margin-left: 10px;margin-top: 10px">全选</el-checkbox>
            <div class="calculationFilter">
              <el-checkbox-group v-model="selectCalculationList" style="display: block">
                <el-checkbox v-for="item in calculationFieldList" :key="item.code" class="check_box" :value="item.code">
                  <div @click.prevent="selectCalculationField(item.code)">{{item.commit}}</div>
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-tab-pane>
        </el-tabs>
        <el-button type="success" class="calculationSumButton" @click="fastSum">快速求和</el-button>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer" align="center" style="margin-top: 20px">
      <el-button type="primary" @click="submitCalculation">确 定</el-button>
      <el-button @click="openCalculation = false">取 消</el-button>
    </div>
  </el-dialog>

  <el-dialog title="编辑报表ID" v-model="openReport" width="1200" append-to-body>
    <el-form ref="reportForm" :model="reportForm" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="主表表名">
            <el-input v-model="reportForm.mainTableName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="子表表名">
            <el-input v-model="reportForm.subTableName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报表编号">
            <el-input v-model="reportForm.reportId"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="同步字段">
            <el-input v-model="reportForm.fieldName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" align="center">
      <el-button type="primary" @click="submitReportForm">确 定</el-button>
      <el-button @click="openReport = false">取 消</el-button>
    </div>
  </el-dialog>

  <div v-if="showImportCascaderDialogFlag" class="" v-drag="['.drag-dialog.el-dialog', '.drag-dialog .el-dialog__header']">
    <el-dialog title="导入选项" v-model="showImportCascaderDialogFlag"
               :show-close="true" class="drag-dialog small-padding-dialog" append-to-body
               :close-on-click-modal="false" :close-on-press-escape="false" :destroy-on-close="true">
      <code-editor v-model="cascaderOptions" mode="json" :readonly="false"></code-editor>
      <template #footer>
        <div class="dialog-footer">
          <el-button size="large" type="primary" @click="saveCascaderOptions">{{i18nt('designer.hint.confirm')}}</el-button>
          <el-button size="large" @click="showImportCascaderDialogFlag = false">{{i18nt('designer.hint.cancel')}}</el-button>
        </div>
      </template>
    </el-dialog>
  </div>

  <div v-if="showImportDialogFlag" class="" v-drag="['.drag-dialog.el-dialog', '.drag-dialog .el-dialog__header']">
    <el-dialog title="导入选项" v-model="showImportDialogFlag"
               :show-close="true" class="drag-dialog small-padding-dialog" append-to-body
               :close-on-click-modal="false" :close-on-press-escape="false" :destroy-on-close="true">
      <el-form-item>
        <el-input type="textarea" rows="10" v-model="optionLines"></el-input>
      </el-form-item>
      <template #footer>
        <div class="dialog-footer">
          <el-button size="large" type="primary" @click="saveOptions">{{i18nt('designer.hint.confirm')}}</el-button>
          <el-button size="large" @click="showImportDialogFlag = false">{{i18nt('designer.hint.cancel')}}</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
  <el-dialog title="文本内容" v-model="openText" width="1200" append-to-body>
    <wang-editor
        style="border: 1px solid gainsboro"
        v-model="helpDocument"
    />
    <div slot="footer" class="dialog-footer" align="center" style="margin-top: 15px">
      <el-button type="primary" @click="submitTextForm">确 定</el-button>
      <el-button @click="openText = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {generateId} from "@/utils/util"
import i18n from "@/utils/i18n";
import CodeEditor from '@/components/code-editor/index'
import fieldAttrConfig from '@/components/vform/config/fieldAttrConfig.json';
/*import {  quillEditor } from 'vue3-quill'*/
//import CalculateEditor from "./calculate-editor"
import WangEditor from  "@/components/WangEditor/index.vue"
import {customSchemas} from "@/components/vform/custom";
import Pinyin from 'tiny-pinyin';

export default {
  name: "tableItem-editor",
  componentName: 'PropertyEditor',
  mixins: [i18n],
  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },
  inject: ['getContainerWidgets','getFieldWidgets','getFieldAttrList','getComparisonTypeList','getCommDictList','getNursingSheetList','getCommDictDetailList','getWinList'],
  components: {
    CodeEditor,
/*    quillEditor,*/
    WangEditor,
  },
//  components:{CalculateEditor},
  data() {
    return {
      checkAllCalculation:false,
      activeNames:"first",
      openText:false,
      helpDocument:"",
      cascaderOptions: '',
      showImportCascaderDialogFlag: false,
      openCalculation:false,
      calculationFilterString:"",
      calculation:"",
      calculationMode:"",
      calculationItem:{},
      selectCalculationList:[],
      openEvent:false,
      eventForm: {},
      eventMode:null,
      eventIndex:0,
      openAction:false,
      actionForm: {},
      actionMode:null,
      actionIndex:0,
      openReport:false,
      reportForm: {},
      reportMode:null,
      reportIndex:0,
      showImportDialogFlag: false,
      optionLines:'',
      separator: '\t',
      fileList:[],
      commDictList:[],
      nursingSheetList:[],
      winList:[],
      defaultMappingFieldList:[
        {type:"main",label:"记录日期",value:"record_date"},
        {type:"main",label:"记录时间",value:"record_time"},
      ],
      mappingFieldList:[
      ],
      eventRules:{
        name: [
          { required: true, message: '名称必填', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '事件类型必填', trigger: 'blur' }
        ],
      },
      caretPosition: 0,
      actionRules:{},
      fieldAttrList:[],
      ruleList:[
        { value: "/^\\d+$/", label: "整数" },
        { value: "/^\\d+(\\.\\d)?$/", label: "一位小数" },
        { value: "/^\\d+(\\.\\d{1,2})?$/", label: "二位小数" },
        { value: "/^\\S+$/", label: "非空" },
        { value: "/^1[3-9]\\d{9}$/", label: "手机号码" },
        { value: "/^[1-9]\\d{5}(18|19|20)?\\d{2}([01]\\d|10)([0-2]\\d|30|31)\\d{3}([0-9Xx])$/", label: "身份证" },
        { value: "/^[\\w-]+@[\\w-]+\\.[a-z]{2,4}$/i", label: "邮箱" }
      ],
      globalParam:[
        { "code": "useUserStore.ward.deptCode", "commit": "系统科室编码" },
        { "code": "useUserStore.ward.deptHisCode", "commit": "HIS中科室编码" },
        { "code": "useUserStore.ward.deptName", "commit": "部门名称" },
        { "code": "useUserStore.ward.pyInput", "commit": "拼音输入码" },
        { "code": "useUserStore.ward.deptSimplename", "commit": "科室简称" },
        { "code": "useUserStore.ward.deptType", "commit": "科室类型项目编码" },
        { "code": "useUserStore.ward.hospitalCode", "commit": "院区编码" },
        { "code": "useUserStore.ward.majorDept", "commit": "大科编码" },
        { "code": "useUserStore.Nhead.userId", "commit": "护士长ID" },
        { "code": "useUserStore.Nhead.guid", "commit": "guid" },
        { "code": "useUserStore.Nhead.userName", "commit": "护士长姓名" },
        { "code": "useUserStore.Nhead.pyInput", "commit": "护士长拼音编码" },
        { "code": "useUserStore.Nhead.staffId", "commit": "护士长工号" },
        { "code": "useUserStore.Nhead.loginId", "commit": "护士长登录账号" },
        { "code": "useUserStore.user.userId", "commit": "用户id" },
        { "code": "useUserStore.user.guid", "commit": "guid" },
        { "code": "useUserStore.user.userHisId", "commit": "用户HisId" },
        { "code": "useUserStore.user.userName", "commit": "用户名称" },
        { "code": "useUserStore.user.pyInput", "commit": "护士拼音输入码" },
        { "code": "useUserStore.user.staffId", "commit": "用户工号" },
        { "code": "useUserStore.user.loginId", "commit": "用户账号" },
        { "code": "useUserStore.patient.deptCode", "commit": "患者系统科室编码" },
        { "code": "useUserStore.patient.deptHisCode", "commit": "患者HIS中科室编码" },
        { "code": "useUserStore.patient.deptName", "commit": "患者部门名称" },
        { "code": "useUserStore.patient.pyInput", "commit": "患者拼音输入码" },
        { "code": "useUserStore.patient.deptSimplename", "commit": "患者科室简称" },
        { "code": "useUserStore.patient.deptType", "commit": "患者科室类型项目编码" },
        { "code": "useUserStore.patient.hospitalCode", "commit": "患者院区编码" },
        { "code": "useUserStore.patient.majorDept", "commit": "患者大科编码" },
        { "code": "useUserStore.patient.inpNo", "commit": "住院号" },
        { "code": "useUserStore.patient.patientId", "commit": "患者唯一ID" },
        { "code": "useUserStore.patient.visitId", "commit": "住院次数" },
        { "code": "useUserStore.patient.isBaby", "commit": "是否婴儿" },
        { "code": "useUserStore.patient.patientName", "commit": "患者姓名" },
        { "code": "useUserStore.patient.pyInput", "commit": "患者拼音输入码" },
        { "code": "useUserStore.patient.sex", "commit": "患者性别" },
        { "code": "useUserStore.patient.birthDate", "commit": "出生日期" },
        { "code": "useUserStore.patient.ageStr", "commit": "患者岁数" },
        { "code": "useUserStore.patient.ehid", "commit": "电子医保凭证" },
        { "code": "useUserStore.patient.admissionTime", "commit": "入院登记时间" },
        { "code": "useUserStore.patient.enrollTime", "commit": "入科室（病区）登记时间" },
        { "code": "useUserStore.patient.deptHisCode", "commit": "HIS中科室编号" },
        { "code": "useUserStore.patient.deptName", "commit": "科室名称" },
        { "code": "useUserStore.patient.admChannel", "commit": "入院途径" },
        { "code": "useUserStore.patient.diagnosis", "commit": "入院诊断" },
        { "code": "useUserStore.patient.bedNo", "commit": "床位号" },
        { "code": "useUserStore.patient.bedSort", "commit": "床位排序" },
        { "code": "useUserStore.patient.doctorName", "commit": "责任医生" },
        { "code": "useUserStore.patient.nurseName", "commit": "责任护士" },
        { "code": "useUserStore.patient.clinicHisCode", "commit": "HIS科室编码" },
        { "code": "useUserStore.patient.clinicName", "commit": "科别名称" },
        { "code": "useUserStore.patient.nurseLevel", "commit": "护理等级" },
        { "code": "useUserStore.patient.diseaseStatus", "commit": "病情状况" },
        { "code": "useUserStore.patient.meal", "commit": "饮食" },
        { "code": "useUserStore.patient.allergy", "commit": "过敏情况" },
        { "code": "useUserStore.patient.prepayments", "commit": "预缴纳金" },
        { "code": "useUserStore.patient.totalCosts", "commit": "实际总费用" },
        { "code": "useUserStore.patient.balance", "commit": "余额" },
        { "code": "useUserStore.patient.hospitalCode", "commit": "院区编码" },
        { "code": "useUserStore.patient.inhosStatus", "commit": "住院状态" },
        { "code": "useUserStore.patient.citizenship", "commit": "国籍" },
        { "code": "useUserStore.patient.nation", "commit": "患者名族" },
        { "code": "useUserStore.patient.marriage", "commit": "婚否" },
        { "code": "useUserStore.patient.job", "commit": "职业" },
        { "code": "useUserStore.patient.idNo", "commit": "身份证号" },
        { "code": "useUserStore.patient.bloodType", "commit": "血型" },
        { "code": "useUserStore.patient.chargeType", "commit": "费用类别" },
        { "code": "useUserStore.patient.phoneNumber1", "commit": "本人第一个电话" },
        { "code": "useUserStore.patient.phoneNumber2", "commit": "本人第二个电话" },
        { "code": "useUserStore.patient.contacts", "commit": "联系人" },
        { "code": "useUserStore.patient.contactsPhone1", "commit": "联系人第一个电话" },
        { "code": "useUserStore.patient.contactsPhone2", "commit": "联系人第二个电话" },
        { "code": "useUserStore.patient.contactsRelation", "commit": "与联系人关系" },
        { "code": "useUserStore.patient.addrProvince", "commit": "省/直辖市" },
        { "code": "useUserStore.patient.addrCity", "commit": "地级市/区" },
        { "code": "useUserStore.patient.addrCountry", "commit": "区/县" },
        { "code": "useUserStore.patient.addrStreet", "commit": "街道" },

      ],
      attrTags:[],
      dateFormatList:[],
      dateTypeList:[],
    }
  },
  computed: {
    fieldList(){
      let fields = [];
      this.getFieldWidgets().forEach(function (val){
        fields.push({label:val.field.options.fieldName+"/"+val.field.options.label,value:val.field.options.fieldName})
      })
      this.getContainerWidgets().forEach(function (val){
        if (val.type == "fy"){
          fields.push({label:val.container.options.fieldName+"/"+val.container.options.label,value:val.container.options.fieldName})
        }
      })
      return fields
    },
    calculationFieldList(){
      let fields = [];
      if (this.activeNames == "first"){
        this.getFieldWidgets().forEach(function (val){
          if (val.type != "static-text"){
            let commit = val.field.options.fieldName+"/"+val.field.options.label
            fields.push({commit:commit,code:val.field.options.fieldName})
          }
        })
        return fields.filter(item => item.commit.includes(this.calculationFilterString))
      }else {
        return this.globalParam.filter(item => item.commit.includes(this.calculationFilterString))
      }
    },
    globalParamList(){
      return this.globalParam.filter(item => item.commit.includes(this.calculationFilterString))
    }
  },
  created() {
    //this.optionModel.fieldType = this.selectedWidget.aliasType;
    //this.optionModel.preSuffix = this.optionModel.label;
    if (!this.optionModel.otherNonGenericAttributes){
      this.optionModel.otherNonGenericAttributes = {}
    }
    this.fieldAttrList = this.getFieldAttrList();
    this.comparisonTypeList = this.getComparisonTypeList()
    this.commDictList = this.getCommDictList();
    this.nursingSheetList = this.getNursingSheetList()
    this.winList = this.getWinList()
    this.initAttrTag();
    this.initDateFormatDict();
    this.initDateTypeDict();
  },
  methods: {
    async initDateTypeDict() {
      let dicDetailList = await this.getCommDictDetailList("dateTypeDict");
      let option = []
      dicDetailList.forEach(function (val) {
        option.push({
          label: val.ITEM_NAME,
          value: val.ITEM_CODE,
        })
      })
      this.dateTypeList = option;
      if (this.optionModel.otherNonGenericAttributes && option.length>0){
        this.optionModel.otherNonGenericAttributes.dateType = option[0].value
      }
    },
    async initDateFormatDict() {
      let dicDetailList = await this.getCommDictDetailList("dateFormatDict");
      let option = []
      dicDetailList.forEach(function (val) {
        option.push({
          label: val.ITEM_NAME,
          value: val.ITEM_CODE,
        })
      })
      this.dateFormatList = option;
      if (this.optionModel.otherNonGenericAttributes && option.length>0){
        this.optionModel.otherNonGenericAttributes.showDateFormat = option[0].value
        this.optionModel.otherNonGenericAttributes.backDateFormat = option[0].value
      }
    },
    async initAttrTag() {
      let dicDetailList = await this.getCommDictDetailList("itemTagDict");
      let option = []
      dicDetailList.forEach(function (val) {
        option.push({
          label: val.ITEM_NAME,
          value: val.ITEM_CODE,
        })
      })
      this.attrTags = option;
    },
    changeActionName(row){
      if (row.name == "jumpWinCtrl"){
        row.openAs = "form"
      }else {
        row.openAs = null
      }
    },
    getPinyinInitials(text) {
      if (!text) return '';

      return Array.from(text).map(char => {
        if (Pinyin.isSupported() && /[\u4e00-\u9fa5]/.test(char)) {
          return Pinyin.convertToPinyin(char)[0].toLowerCase(); // 取首字母并转为大写
        }
        return char; // 非中文字符直接返回
      }).join('');
    },
    setFieldName(){
      let label = this.optionModel.label
      if (label){
        this.optionModel.fieldName = this.getPinyinInitials(label);
      }
    },
    async changeCommDict(code){
      if (localStorage.getItem("accessToken")){
        let dicDetailList = await this.getCommDictDetailList(code);
        let option = []
        dicDetailList.forEach(function (val) {
          option.push({
            label:val.ITEM_NAME,
            value:val.ITEM_CODE,
          })
        })
        this.optionModel.bindingData.option = option;
      }
    },
    changeLabel(label){
      if (!this.optionModel.preSuffix){
        this.optionModel.preSuffix = label
      }
    },
    changeNursingSheet(row){
      let FUNCNO = row.funcNo
      let sheet = {};
      this.nursingSheetList.forEach(function (value) {
        if (value.FUNCNO == FUNCNO){
          sheet = value
          return
        }
      })
      let configJson = JSON.parse(sheet.CONFIG_JSON);
      let fieldDefs = configJson.fieldDefs;
      let mappingFieldList = [...this.defaultMappingFieldList]
      fieldDefs.forEach(function (item){
        if (item.fieldType != "text"){
          mappingFieldList.push({type:"sub",label:item.preSuffix,value:item.fieldName})
        }
      })
      this.mappingFieldList = mappingFieldList;
      row.mappingFieldName = null;
    },
    changeMappingField(row){
      let val = row.mappingFieldName;
      let item = {};
      this.mappingFieldList.forEach(function (value) {
        if (value.value == val){
          item = value
          return
        }
      })
      row.type = item.type;
      row.mappingFieldName = item.value;
    },
    handleImgSuccess(event){
      const file = event.target.files[0];
      const self = this;
      if (file) {
        const reader = new FileReader();
        reader.onload = function (e) {
          const base64String = e.target.result;
          self.optionModel.pictureAddress = base64String;
        };
        reader.readAsDataURL(file);
      }
    },
    editFillText(){
      this.openText = true;
      this.helpDocument = this.optionModel.preSuffix
    },
    submitTextForm(){
      this.openText = false;
      this.optionModel.preSuffix = this.helpDocument
    },
    importOptions() {
      this.optionLines = ''
      if (this.optionModel.bindingData.option.length > 0) {
        this.optionModel.bindingData.option.forEach((opt) => {
          if (opt.value){
            if (opt.value === opt.label) {
              this.optionLines += opt.value + '\n'
            } else {
              this.optionLines += opt.fieldName + this.separator + opt.label + this.separator + opt.value + '\n'
            }
          }
        })
      }
      this.showImportDialogFlag = true
    },
    saveOptions() {
      let lineArray = this.optionLines.split('\n')
      //console.log('test', lineArray)
      if (lineArray.length > 0) {
        this.optionModel.bindingData.option = []
        lineArray.forEach((optLine) => {
          if (!!optLine && !!optLine.trim()) {
            console.log(optLine)
            if (optLine.indexOf(this.separator) !== -1) {
              this.optionModel.bindingData.option.push({
                fieldName: optLine.split(this.separator)[0],
                label: optLine.split(this.separator)[1],
                value: optLine.split(this.separator)[2],

              })
            } else {
              this.optionModel.bindingData.option.push({
                value: optLine,
                label: optLine
              })
            }
          }
        })
      } else {
        this.optionModel.bindingData.option = []
      }

      this.showImportDialogFlag = false
    },
    changeAdditionalFlag(value){
      if (value == "temperature" || value == "JWHTW"){
        this.optionModel.rules.regularExpression = "^(3([4-9])|4([0-3]))(\\.|(\\.[0-9]))?(Y|G|K|E|y|g|k|e)?$";
        this.optionModel.rules.failurePrompt = "34~43的单位为(°C)的数字";
      }else if (value == "pulse" || value == "XL"){
        this.optionModel.rules.regularExpression = "^([0-9]|\\d{0}|1[0-9]|\\d{1}|1[0-9][0-9]|\\d{2}|200)(P|p)?$";
        this.optionModel.rules.failurePrompt = "0~200的单位为(次/分)的数字";
      }else if (value == "breath"){
        this.optionModel.rules.regularExpression = "^([0-9]|\\d{0}|1[0-9]|\\d{1}|1[0-1][0-9]|\\d{2}|120)(R|r)?$";
        this.optionModel.rules.failurePrompt = "0~120的单位为(次/分)的数字";
      }
    },
    showFieldAttr(attrCode){
      let fieldAttrConfigList = [];
      if (this.fieldAttrList.length == 0){
        fieldAttrConfigList = fieldAttrConfig;
      }else {
        fieldAttrConfigList = this.fieldAttrList;
      }
      // 使用find方法查找匹配的对象
      let fieldTypeCode = this.selectedWidget.aliasType;
      const item = fieldAttrConfigList.find(element =>
          element.FIELD_TYPE_CODE == fieldTypeCode && element.ATTR_CODE == attrCode
      );
      if (!item){
        return true;
      }else {
        if (item.NEED == 1){
          return true;
        }else {
          return false;
        }
      }
    },
    importCascaderOptions() {
      this.cascaderOptions = JSON.stringify(this.optionModel.optionItems, null, '  ')
      this.showImportCascaderDialogFlag = true
    },

    saveCascaderOptions() {
      try {
        let newOptions = JSON.parse(this.cascaderOptions)
        this.optionModel.bindingData.option = newOptions
        //TODO: 是否需要重置选项默认值？？

        this.showImportCascaderDialogFlag = false
      } catch (ex) {
        this.$message.error(this.i18nt('designer.hint.invalidOptionsData') + ex.message)
      }
    },
    goEditCalculated(mode,value,item){
      this.calculationMode = mode;
      this.calculation = value?value:"";
      this.calculationItem = item;
      this.openCalculation = true;
      const self = this;
      setTimeout(function () {
        self.$refs["calculationInput"].focus();
      }, 200);
    },
    changeCalculation(){
      this.selectCalculationList = []
      this.checkAllCalculation = false
    },
    checkAllCalculationFieldList(){
      if (this.checkAllCalculation){
        this.calculationFieldList.forEach(element => {
          this.selectCalculationList.push(element.code)
        })
      }else {
        this.selectCalculationList = []
      }
    },
    selectCalculationField(item){
      let dom = this.$refs["calculationInput"].textarea;
      let index = dom.selectionStart;
      let label = "#"+item+"#";
      let text = this.calculation;
      const beforeCaret = text.slice(0, index);
      const afterCaret = text.slice(index);
      let calculation = beforeCaret+label+afterCaret
      this.calculation = calculation;
      this.$nextTick(() => {  //必须在DOM更新之后操作
        dom.focus();
        dom.setSelectionRange(   // 光标位置
            index + label.length,
            index + label.length
        );
      })
    },
    fastSum(){
      let selectCalculationList = [];
      this.selectCalculationList.forEach(element => {
        selectCalculationList.push("#"+element+"#")
      })
      let text = this.calculation;
      if (text){
        text = text + "+"
      }
      text = text + selectCalculationList.join("+")
      this.calculation = text;
    },
    submitCalculation(){
      this.openCalculation = false;
      if (this.calculationMode == "fieldDef"){
        this.optionModel.calculatedFields = this.calculation;
      }else if (this.calculationMode == "initializedExpressions"){
        this.optionModel.initializedExpressions.expression = this.calculation;
      }else {
        this.calculationItem.changeTo = this.calculation;
      }
    },
    addRange(){
      this.optionModel.initializedExpressions.range.push({max:null,min:null,result:null})
    },
    deleteRange(index){
      this.optionModel.initializedExpressions.range.splice(index, 1)
    },
    addBindingDataOption(){
      this.optionModel.bindingData.option.push({})
    },
    bindKey(){
      let option = this.optionModel.bindingData.option;
      let fieldName = this.optionModel.fieldName
      option.forEach(function (val,index) {
        val.fieldName = fieldName+"_"+(index+1)
      })
    },
    deleteBindingDataOption(index){
      this.optionModel.bindingData.option.splice(index, 1)
    },
    addCondition(){
      if (!this.eventForm.condition){
        this.eventForm.condition = []
      }
      this.eventForm.condition.push({value:[],comparisonType:null,linkType:"and",fieldName:null})
    },
    deleteCondition(index){
      this.eventForm.condition.splice(index, 1)
    },
    addEvent(){
      this.eventForm = {
        type: "valueChange",
        name:"值Change事件",
      }
      this.openEvent = true
      this.eventMode = "add";
    },
    deleteEvent(index){
      this.optionModel.changeEvent.splice(index, 1)
    },
    editEvent(item,index){
      this.eventForm = {...item}
      this.openEvent = true
      this.eventMode = "edit";
      this.eventIndex = index;
    },
    submitBtnForm() {
      this.$refs['eventForm'].validate(valid => {
        if (valid) {
          if (this.eventMode == "add") {
            this.optionModel.changeEvent.push({...this.eventForm})
            this.openEvent = false;
          }else {
            this.optionModel.changeEvent[this.eventIndex] = {...this.eventForm}
            this.openEvent = false;
          }
        }
      })
    },
    addAction(){
      if (!this.eventForm.actions){
        this.eventForm.actions = []
      }
      this.eventForm.actions.push({refreshField:[],refreshFunc:{}})
/*      this.actionForm = {
        "name":"readOnlyCtrl",
        "refresh": {
          "mainArgs": [],
          "detailArgs": [],
          "refreshFunc": [],
          "refreshField": [],
          "requestParams": {},
          "updateFieldValue": [],
        }
      }
      this.openAction = true
      this.actionMode = "add";*/
    },
    deleteAction(index){
      this.eventForm.actions.splice(index, 1)
    },
    /*editAction(item,index){
      this.actionForm = {...item}
      this.openAction = true
      this.actionMode = "edit";
      this.actionIndex = index;
    },
    deleteAction(index){
      this.eventForm.actions.splice(index, 1)
    },
    submitActionForm() {
      this.$refs['actionForm'].validate(valid => {
        if (valid) {
          if (this.actionMode == "add") {
            if (!this.eventForm.actions){
              this.eventForm.actions = []
            }
            this.eventForm.actions.push({...this.actionForm})
            this.openAction = false;
          }else {
            this.eventForm.actions[this.actionIndex] = {...this.actionForm}
            this.openAction = false;
          }
        }
      })
    },*/
    addReport(){
      this.reportForm = {
      }
      this.openReport = true
      this.reportMode = "add";
    },
    editReport(item,index){
      this.reportForm = {...item}
      this.openReport = true
      this.reportMode = "edit";
      this.reportIndex = index;
    },
    deleteReport(index){
      this.optionModel.syncData.splice(index, 1)
    },
    submitReportForm() {
      this.$refs['reportForm'].validate(valid => {
        if (valid) {
          if (this.reportMode == "add") {
            this.optionModel.syncData.push({...this.reportForm})
            this.openReport = false;
          }else {
            this.optionModel.syncData[this.reportIndex] = {...this.reportForm}
            this.openReport = false;
          }
        }
      })
    },
    addUpdateField(){
      if (!this.actionForm.refresh.updateFieldValue){
        this.actionForm.refresh.updateFieldValue = []
      }
      this.actionForm.refresh.updateFieldValue.push({fieldName:null,changeTo:null})
    },
    deleteUpdateField(index){
      this.actionForm.refresh.updateFieldValue.splice(index, 1)
    },

  }
}
</script>

<style lang="scss">
.demo-tabs .el-tabs__header{
  margin-bottom: 0px;
}
.calculationSumButton{
  margin-top: 5px;
}
  .calculationFilter{
    width: 100%;
    height: 345px;
    overflow-y: auto;
    box-sizing: border-box;
    border: 1px solid gainsboro;
    border-radius: 5px;
    margin-top: 8px;
    overflow-x: hidden;
    .check_box{
      width: 100%;
      height: 30px !important;
      line-height: 30px !important;;
      padding-left: 15px;
      padding-right: 15px;
      box-sizing: border-box;
      border-bottom: 1px solid gainsboro;
      cursor: pointer;
      .el-checkbox__label{
         height: 100%;
         line-height: 30px !important;
         width: 100%;
      }
      &:hover{
        background-color: #e5e5e5;
      }
    }
  }
  ::v-deep.hide .el-upload--picture-card {
    display: none;
  }
</style>
